package com.ctg.behavior.calc.impala.engine;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.ctg.behavior.client.impala.CtImpalaClient;
import com.ctg.behavior.client.impala.common.CtQueryResult;
import com.ctg.behavior.utils.CtDateUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class ImpalaSQLEngine {

	@Autowired
	private CtImpalaClient impalaClient;

	/******************************************
	 * @param queryType
	 * @param sql
	 * @return
	 */
	public CtQueryResult doQuery(String queryType, String sql) {
		CtQueryResult queryResult = new CtQueryResult();
		queryResult.setSql(sql);
		log.info("sqlEngine-type:{}-sql:{}", queryType, sql);
		log.info("sqlEngine-type:{}-time-start: {}", queryType, CtDateUtils.getCurrentDateSSS());
		queryResult = impalaClient.doQuery(queryType, sql);
		log.info("sqlEngine-type:{}-time-end  : {}", queryType, CtDateUtils.getCurrentDateSSS());
		log.info("sqlEngine-type:{}-queryResult={}", queryType, JSON.toJSONString(queryResult));
		return queryResult;
	}

}
